home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb / foo / m-convex.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-23  |  21.6 KB  |  610 lines

  1. /* Definitions to make GDB run on Convex Unix (4bsd)
  2.    Copyright (C) 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. GDB is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GDB is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GDB; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* Describe the endian nature of this machine.  */
  21. #define BITS_BIG_ENDIAN
  22. #define BYTES_BIG_ENDIAN
  23. #define WORDS_BIG_ENDIAN
  24.  
  25. /* Include certain files for dbxread.c  */
  26. #include <convex/filehdr.h>
  27. #include <convex/opthdr.h>
  28. #include <convex/scnhdr.h>
  29. #include <nlist.h>
  30.  
  31. #define LONG_LONG
  32. #define ATTACH_DETACH
  33. #define HAVE_WAIT_STRUCT
  34. #define NO_SIGINTERRUPT
  35.  
  36. /* Get rid of any system-imposed stack limit if possible.  */
  37.  
  38. #define SET_STACK_LIMIT_HUGE
  39.  
  40. /* Define this if the C compiler puts an underscore at the front
  41.    of external names before giving them to the linker.  */
  42.  
  43. #define NAMES_HAVE_UNDERSCORE
  44.  
  45. /* Debugger information will be in DBX format.  */
  46.  
  47. #define READ_DBX_FORMAT
  48.  
  49. /* There is come problem with the debugging symbols generated by the
  50.    compiler such that the debugging symbol for the first line of a
  51.    function overlap with the function prologue.  */
  52. #define PROLOGUE_FIRSTLINE_OVERLAP
  53.  
  54. /* When convex pcc says CHAR or SHORT, it provides the correct address.  */
  55.  
  56. #define BELIEVE_PCC_PROMOTION 1
  57.  
  58. /* Symbol types to ignore.  */
  59. /* 0xc4 is N_MONPT.  Use the numeric value for the benefit of people
  60.    with (rather) old OS's.  */
  61. #define IGNORE_SYMBOL(TYPE) \
  62.     (((TYPE) & ~N_EXT) == N_TBSS       \
  63.      || ((TYPE) & ~N_EXT) == N_TDATA   \
  64.      || ((TYPE) & ~N_EXT) == 0xc4)
  65.  
  66. /* Use SIGCONT rather than SIGTSTP because convex Unix occasionally
  67.    turkeys SIGTSTP.  I think.  */
  68.  
  69. #define STOP_SIGNAL SIGCONT
  70.  
  71. /* Convex ld sometimes omits _etext.
  72.    Get text segment end from a.out header in this case.  */
  73.  
  74. extern unsigned text_end;
  75. #define END_OF_TEXT_DEFAULT text_end
  76.  
  77. /* Use csh to do argument expansion so we get ~ and such.  */
  78.  
  79. /* Doesn't work.  */
  80. /* #define SHELL_FILE "/bin/csh" */
  81.  
  82. /* Offset from address of function to start of its code.
  83.    Zero on most machines.  */
  84.  
  85. #define FUNCTION_START_OFFSET 0
  86.  
  87. /* Advance PC across any function entry prologue instructions
  88.    to reach some "real" code.
  89.    Convex prolog is:
  90.        [sub.w #-,sp]        in one of 3 possible sizes
  91.        [mov psw,-        fc/vc main program prolog
  92.         and #-,-          (skip it because the "mov psw" saves the
  93.     mov -,psw]           T bit, so continue gets a surprise trap)
  94.        [and #-,sp]        fc/vc O2 main program prolog
  95.        [ld.- -(ap),-]        pcc/gcc register arg loads
  96. */
  97.  
  98. #define SKIP_PROLOGUE(pc)  \
  99. { int op, ix;                                \
  100.   op = read_memory_integer (pc, 2);                    \
  101.   if ((op & 0xffc7) == 0x5ac0) pc += 2;                    \
  102.   else if (op == 0x1580) pc += 4;                    \
  103.   else if (op == 0x15c0) pc += 6;                    \
  104.   if ((read_memory_integer (pc, 2) & 0xfff8) == 0x7c40            \
  105.       && (read_memory_integer (pc + 2, 2) & 0xfff8) == 0x1240        \
  106.       && (read_memory_integer (pc + 8, 2) & 0xfff8) == 0x7c48)        \
  107.     pc += 10;                                \
  108.   if (read_memory_integer (pc, 2) == 0x1240) pc += 6;            \
  109.   for (;;) {                                \
  110.     op = read_memory_integer (pc, 2);                    \
  111.     ix = (op >> 3) & 7;                            \
  112.     if (ix != 6) break;                            \
  113.     if ((op & 0xfcc0) == 0x3000) pc += 4;                \
  114.     else if ((op & 0xfcc0) == 0x3040) pc += 6;                \
  115.     else if ((op & 0xfcc0) == 0x2800) pc += 4;                \
  116.     else if ((op & 0xfcc0) == 0x2840) pc += 6;                \
  117.     else break;}}
  118.  
  119. /* Immediately after a function call, return the saved pc.
  120.    (ignore frame and return *$sp so we can handle both calls and callq) */
  121.  
  122. #define SAVED_PC_AFTER_CALL(frame) \
  123.     read_memory_integer (read_register (SP_REGNUM), 4)
  124.  
  125. /* Address of end of stack space.
  126.    This is ((USRSTACK + 0xfff) & -0x1000)) from <convex/vmparam.h> but
  127.    that expression depends on the kernel version; instead, fetch a
  128.    page-zero pointer and get it from that.  This will be invalid if
  129.    they ever change the way bkpt signals are delivered.  */
  130.  
  131. #define STACK_END_ADDR (0xfffff000 & *(unsigned *) 0x80000050)
  132.  
  133. /* User-mode traps push an extended rtn block,
  134.    then fault with one of the following PCs */
  135.  
  136. #define is_trace_pc(pc)  ((unsigned) ((pc) - (*(int *) 0x80000040)) <= 4)
  137. #define is_arith_pc(pc)  ((unsigned) ((pc) - (*(int *) 0x80000044)) <= 4)
  138. #define is_break_pc(pc)  ((unsigned) ((pc) - (*(int *) 0x80000050)) <= 4)
  139.  
  140. /* We need to manipulate trap bits in the psw */
  141.  
  142. #define PSW_TRAP_FLAGS    0x69670000
  143. #define PSW_T_BIT    0x08000000
  144. #define PSW_S_BIT    0x01000000
  145.  
  146. /* Stack grows downward.  */
  147.  
  148. #define INNER_THAN <
  149.  
  150. /* Sequence of bytes for breakpoint instruction. (bkpt)  */
  151.  
  152. #define BREAKPOINT {0x7d,0x50}
  153.  
  154. /* Amount PC must be decremented by after a breakpoint.
  155.    This is often the number of bytes in BREAKPOINT but not always.
  156.    (The break PC needs to be decremented by 2, but we do it when the
  157.    break frame is recognized and popped.  That way gdb can tell breaks
  158.    from trace traps with certainty.) */
  159.  
  160. #define DECR_PC_AFTER_BREAK 0
  161.  
  162. /* Nonzero if instruction at PC is a return instruction. (rtn or rtnq) */
  163.  
  164. #define ABOUT_TO_RETURN(pc) \
  165.     ((read_memory_integer (pc, 2) & 0xffe0) == 0x7c80)
  166.  
  167. /* Return 1 if P points to an invalid floating point value. */
  168.  
  169. #define INVALID_FLOAT(p,len)   0
  170.  
  171. /* Largest integer type */
  172.  
  173. #define LONGEST long long
  174.  
  175. /* Name of the builtin type for the LONGEST type above.  */
  176.  
  177. #undef BUILTIN_TYPE_LONGEST
  178. #define BUILTIN_TYPE_LONGEST builtin_type_long_long
  179.  
  180. /* Say how long (ordinary) registers are.  */
  181.  
  182. #define REGISTER_TYPE long long
  183.  
  184. /* Number of machine registers */
  185.  
  186. #define NUM_REGS 26
  187.  
  188. /* Initializer for an array of names of registers.
  189.    There should be NUM_REGS strings in this initializer.  */
  190.  
  191. #define REGISTER_NAMES {"pc","psw","fp","ap","a5","a4","a3","a2","a1","sp",\
  192.             "s7","s6","s5","s4","s3","s2","s1","s0",\
  193.             "S7","S6","S5","S4","S3","S2","S1","S0"}
  194.  
  195. /* Register numbers of various important registers.
  196.    Note that some of these values are "real" register numbers,
  197.    and correspond to the general registers of the machine,
  198.    and some are "phony" register numbers which are too large
  199.    to be actual register numbers as far as the user is concerned
  200.    but do serve to get the desired values when passed to read_register.  */
  201.  
  202. #define S0_REGNUM 25        /* the real S regs */
  203. #define S7_REGNUM 18
  204. #define s0_REGNUM 17        /* low-order halves of S regs */
  205. #define s7_REGNUM 10
  206. #define SP_REGNUM 9         /* A regs */
  207. #define A1_REGNUM 8
  208. #define A5_REGNUM 4
  209. #define AP_REGNUM 3
  210. #define FP_REGNUM 2        /* Contains address of executing stack frame */
  211. #define PS_REGNUM 1        /* Contains processor status */
  212. #define PC_REGNUM 0        /* Contains program counter */
  213.  
  214. /* convert dbx stab register number (from `r' declaration) to a gdb REGNUM */
  215.  
  216. #define STAB_REG_TO_REGNUM(value) \
  217.       ((value) < 8 ? S0_REGNUM - (value) : SP_REGNUM - ((value) - 8))
  218.  
  219. /* Vector register numbers, not handled as ordinary regs.
  220.    They are treated as convenience variables whose values are read
  221.    from the inferior when needed.  */
  222.  
  223. #define V0_REGNUM 0
  224. #define V7_REGNUM 7
  225. #define VM_REGNUM 8
  226. #define VS_REGNUM 9
  227. #define VL_REGNUM 10
  228.  
  229. /* Total amount of space needed to store our copies of the machine's
  230.    register state, the array `registers'.  */
  231. #define REGISTER_BYTES (4*10 + 8*8)
  232.  
  233. /* Index within `registers' of the first byte of the space for
  234.    register N.
  235.    NB: must match structure of struct syscall_context for correct operation */
  236.  
  237. #define REGISTER_BYTE(N) ((N) < s7_REGNUM ? 4*(N) : \
  238.               (N) < S7_REGNUM ? 44 + 8 * ((N)-s7_REGNUM) : \
  239.                                 40 + 8 * ((N)-S7_REGNUM))
  240.  
  241. /* Number of bytes of storage in the actual machine representation
  242.    for register N. */
  243.  
  244. #define REGISTER_RAW_SIZE(N) ((N) < S7_REGNUM ? 4 : 8)
  245.  
  246. /* Number of bytes of storage in the program's representation
  247.    for register N.   */
  248.  
  249. #define REGISTER_VIRTUAL_SIZE(N) REGISTER_RAW_SIZE(N)
  250.  
  251. /* Largest value REGISTER_RAW_SIZE can have.  */
  252.  
  253. #define MAX_REGISTER_RAW_SIZE 8
  254.  
  255. /* Largest value REGISTER_VIRTUAL_SIZE can have.  */
  256.  
  257. #define MAX_REGISTER_VIRTUAL_SIZE 8
  258.  
  259. /* Nonzero if register N requires conversion
  260.    from raw format to virtual format.  */
  261.  
  262. #define REGISTER_CONVERTIBLE(N) 0
  263.  
  264. /* Convert data from raw format for register REGNUM
  265.    to virtual format for register REGNUM.  */
  266.  
  267. #define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO)    \
  268.    bcopy ((FROM), (TO), REGISTER_RAW_SIZE (REGNUM));
  269.  
  270. /* Convert data from virtual format for register REGNUM
  271.    to raw format for register REGNUM.  */
  272.  
  273. #define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO)    \
  274.   bcopy ((FROM), (TO), REGISTER_RAW_SIZE (REGNUM));
  275.  
  276. /* Return the GDB type object for the "standard" data type
  277.    of data in register N.  */
  278.  
  279. #define REGISTER_VIRTUAL_TYPE(N) \
  280.    ((N) < S7_REGNUM ? builtin_type_int : builtin_type_long_long)
  281.  
  282. /* Store the address of the place in which to copy the structure the
  283.    subroutine will return.  This is called from call_function. */
  284.  
  285. #define STORE_STRUCT_RETURN(ADDR, SP) \
  286.   { write_register (A1_REGNUM, (ADDR)); }
  287.  
  288. /* Extract from an array REGBUF containing the (raw) register state
  289.    a function return value of type TYPE, and copy that, in virtual format,
  290.    into VALBUF.  */
  291.  
  292. #define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
  293.   bcopy (&((char *) REGBUF) [REGISTER_BYTE (S0_REGNUM) + \
  294.                  8 - TYPE_LENGTH (TYPE)],\
  295.      VALBUF, TYPE_LENGTH (TYPE))
  296.  
  297. /* Write into appropriate registers a function return value
  298.    of type TYPE, given in virtual format.  */
  299.  
  300. #define STORE_RETURN_VALUE(TYPE,VALBUF) \
  301.     write_register_bytes (REGISTER_BYTE (S0_REGNUM), VALBUF, 8)
  302.  
  303. /* Extract from an array REGBUF containing the (raw) register state
  304.    the address in which a function should return its structure value,
  305.    as a CORE_ADDR (or an expression that can be used as one).  */
  306.  
  307. #define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) \
  308.     (*(int *) & ((char *) REGBUF) [REGISTER_BYTE (s0_REGNUM)])
  309.  
  310. /* Compensate for lack of `vprintf' function.  */
  311. #ifndef HAVE_VPRINTF
  312. #define vprintf(format, ap) _doprnt (format, ap, stdout)
  313. #endif /* not HAVE_VPRINTF */
  314.  
  315. /* Define trapped internal variable hooks to read and write
  316.    vector and communication registers.  */
  317.  
  318. #define IS_TRAPPED_INTERNALVAR is_trapped_internalvar
  319. #define VALUE_OF_TRAPPED_INTERNALVAR value_of_trapped_internalvar
  320. #define SET_TRAPPED_INTERNALVAR set_trapped_internalvar
  321.  
  322. extern struct value *value_of_trapped_internalvar ();
  323.  
  324. /* Hooks to read data from soff exec and core files,
  325.    and to describe the files.  */
  326.  
  327. #define XFER_CORE_FILE
  328. #define FILES_INFO_HOOK print_maps
  329.  
  330. /* Hook to call after creating inferior process.  */
  331.  
  332. #define CREATE_INFERIOR_HOOK create_inferior_hook
  333.  
  334. /* Hook to call to print a typeless integer value, normally printed in decimal.
  335.    For convex, use hex instead if the number looks like an address.  */
  336.  
  337. #define PRINT_TYPELESS_INTEGER decout
  338.  
  339. /* For the native compiler, variables for a particular lexical context
  340.    are listed after the beginning LBRAC instead of before in the
  341.    executables list of symbols.  Using "gcc_compiled." to distinguish
  342.    between GCC and native compiler doesn't work on Convex because the
  343.    linker sorts the symbols to put "gcc_compiled." in the wrong place.
  344.    desc is nonzero for native, zero for gcc.   */
  345. #define VARIABLES_INSIDE_BLOCK(desc) (desc != 0)
  346.  
  347. /* Pcc occaisionally puts an SO where there should be an SOL.   */
  348. #define PCC_SOL_BROKEN
  349.  
  350. /* Cannot execute with pc on the stack.  */
  351. #define CANNOT_EXECUTE_STACK
  352.  
  353. /* Describe the pointer in each stack frame to the previous stack frame
  354.    (its caller).  */
  355.  
  356. /* FRAME_CHAIN takes a frame_info with a frame's nominal address in fi->frame,
  357.    and produces the frame's chain-pointer.
  358.  
  359.    FRAME_CHAIN_COMBINE takes the chain pointer and the frame's nominal address
  360.    and produces the nominal address of the caller frame.
  361.  
  362.    However, if FRAME_CHAIN_VALID returns zero,
  363.    it means the given frame is the outermost one and has no caller.
  364.    In that case, FRAME_CHAIN_COMBINE is not used.  */
  365.  
  366. /* (caller fp is saved at 8(fp)) */
  367.  
  368. #define FRAME_CHAIN(fi)   (read_memory_integer ((fi)->frame + 8, 4))
  369.  
  370. #define FRAME_CHAIN_VALID(chain, thisframe) \
  371.   (chain != 0 && (outside_startup_file (FRAME_SAVED_PC (thisframe))))
  372.  
  373. #define FRAME_CHAIN_COMBINE(chain, thisframe) (chain)
  374.  
  375. /* Define other aspects of the stack frame.  */
  376.  
  377. /* A macro that tells us whether the function invocation represented
  378.    by FI does not have a frame on the stack associated with it.  If it
  379.    does not, FRAMELESS is set to 1, else 0.
  380.    On convex, check at the return address for `callq' -- if so, frameless,
  381.    otherwise, not.  */
  382.  
  383. #define FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) \
  384. {                                     \
  385.   extern CORE_ADDR text_start, text_end;                \
  386.   CORE_ADDR call_addr = SAVED_PC_AFTER_CALL (FI);            \
  387.   (FRAMELESS) = (call_addr >= text_start && call_addr < text_end    \
  388.          && read_memory_integer (call_addr - 6, 1) == 0x22);    \
  389. }
  390.  
  391. #define FRAME_SAVED_PC(fi) (read_memory_integer ((fi)->frame, 4))
  392.  
  393. #define FRAME_ARGS_ADDRESS(fi) (read_memory_integer ((fi)->frame + 12, 4))
  394.  
  395. #define FRAME_LOCALS_ADDRESS(fi) (fi)->frame
  396.  
  397. /* Return number of args passed to a frame.
  398.    Can return -1, meaning no way to tell.  */
  399.  
  400. #define FRAME_NUM_ARGS(numargs, fi)  \
  401. { numargs = read_memory_integer (FRAME_ARGS_ADDRESS (fi) - 4, 4); \
  402.   if (numargs < 0 || numargs >= 256) numargs = -1;}
  403.  
  404. /* Return number of bytes at start of arglist that are not really args.  */
  405.  
  406. #define FRAME_ARGS_SKIP 0
  407.  
  408. /* Put here the code to store, into a struct frame_saved_regs,
  409.    the addresses of the saved registers of frame described by FRAME_INFO.
  410.    This includes special registers such as pc and fp saved in special
  411.    ways in the stack frame.  sp is even more special:
  412.    the address we return for it IS the sp for the next frame.  */
  413.  
  414. /* Normal (short) frames save only PC, FP, (callee's) AP.  To reasonably
  415.    handle gcc and pcc register variables, scan the code following the
  416.    call for the instructions the compiler inserts to reload register
  417.    variables from stack slots and record the stack slots as the saved
  418.    locations of those registers.  This will occasionally identify some
  419.    random load as a saved register; this is harmless.  vc does not
  420.    declare its register allocation actions in the stabs.  */
  421.  
  422. #define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs)        \
  423. { register int regnum;                            \
  424.   register int frame_length =    /* 3 short, 2 long, 1 extended, 0 context */\
  425.       (read_memory_integer ((frame_info)->frame + 4, 4) >> 25) & 3;    \
  426.   register CORE_ADDR frame_fp =                        \
  427.       read_memory_integer ((frame_info)->frame + 8, 4);            \
  428.   register CORE_ADDR next_addr;                        \
  429.   bzero (&frame_saved_regs, sizeof frame_saved_regs);            \
  430.   (frame_saved_regs).regs[PC_REGNUM] = (frame_info)->frame + 0;        \
  431.   (frame_saved_regs).regs[PS_REGNUM] = (frame_info)->frame + 4;        \
  432.   (frame_saved_regs).regs[FP_REGNUM] = (frame_info)->frame + 8;        \
  433.   (frame_saved_regs).regs[AP_REGNUM] = frame_fp + 12;            \
  434.   next_addr = (frame_info)->frame + 12;                    \
  435.   if (frame_length < 3)                            \
  436.     for (regnum = A5_REGNUM; regnum < SP_REGNUM; ++regnum)        \
  437.       (frame_saved_regs).regs[regnum] = (next_addr += 4);        \
  438.   if (frame_length < 2)                            \
  439.     (frame_saved_regs).regs[SP_REGNUM] = (next_addr += 4);        \
  440.   next_addr -= 4;                            \
  441.   if (frame_length < 3)                            \
  442.     for (regnum = S7_REGNUM; regnum < S0_REGNUM; ++regnum)        \
  443.       (frame_saved_regs).regs[regnum] = (next_addr += 8);        \
  444.   if (frame_length < 2)                            \
  445.     (frame_saved_regs).regs[S0_REGNUM] = (next_addr += 8);        \
  446.   else                                    \
  447.     (frame_saved_regs).regs[SP_REGNUM] = next_addr + 8;            \
  448.   if (frame_length == 3) {                        \
  449.     CORE_ADDR pc = read_memory_integer ((frame_info)->frame, 4);    \
  450.     int op, ix, disp;                            \
  451.     op = read_memory_integer (pc, 2);                    \
  452.     if ((op & 0xffc7) == 0x1480) pc += 4;     /* add.w #-,sp */    \
  453.     else if ((op & 0xffc7) == 0x58c0) pc += 2;    /* add.w #-,sp */    \
  454.     op = read_memory_integer (pc, 2);                    \
  455.     if ((op & 0xffc7) == 0x2a06) pc += 4;    /* ld.w -,ap */        \
  456.     for (;;) {                                \
  457.       op = read_memory_integer (pc, 2);                    \
  458.       ix = (op >> 3) & 7;                        \
  459.       if ((op & 0xfcc0) == 0x2800) {        /* ld.- -,ak */        \
  460.         regnum = SP_REGNUM - (op & 7);                    \
  461.     disp = read_memory_integer (pc + 2, 2);                \
  462.     pc += 4;}                            \
  463.       else if ((op & 0xfcc0) == 0x2840) {    /* ld.- -,ak */        \
  464.         regnum = SP_REGNUM - (op & 7);                    \
  465.     disp = read_memory_integer (pc + 2, 4);                \
  466.     pc += 6;}                            \
  467.       if ((op & 0xfcc0) == 0x3000) {        /* ld.- -,sk */        \
  468.         regnum = S0_REGNUM - (op & 7);                    \
  469.     disp = read_memory_integer (pc + 2, 2);                \
  470.     pc += 4;}                            \
  471.       else if ((op & 0xfcc0) == 0x3040) {    /* ld.- -,sk */        \
  472.         regnum = S0_REGNUM - (op & 7);                    \
  473.     disp = read_memory_integer (pc + 2, 4);                \
  474.     pc += 6;}                            \
  475.       else if ((op & 0xff00) == 0x7100) {    /* br crossjump */    \
  476.         pc += 2 * (char) op;                        \
  477.         continue;}                            \
  478.       else if (op == 0x0140) {            /* jmp crossjump */    \
  479.         pc = read_memory_integer (pc + 2, 4);                \
  480.         continue;}                            \
  481.       else break;                            \
  482.       if ((frame_saved_regs).regs[regnum])                \
  483.     break;                                \
  484.       if (ix == 7) disp += frame_fp;                    \
  485.       else if (ix == 6) disp += read_memory_integer (frame_fp + 12, 4);    \
  486.       else if (ix != 0) break;                        \
  487.       (frame_saved_regs).regs[regnum] =                    \
  488.     disp - 8 + (1 << ((op >> 8) & 3));                \
  489.       if (regnum >= S7_REGNUM)                        \
  490.         (frame_saved_regs).regs[regnum - S0_REGNUM + s0_REGNUM] =    \
  491.       disp - 4 + (1 << ((op >> 8) & 3));                \
  492.     }                                    \
  493.   }                                    \
  494. }
  495.  
  496. /* Things needed for making the inferior call functions.  */
  497.  
  498. /* Push an empty stack frame, to record the current PC, etc.  */
  499.  
  500. #define PUSH_DUMMY_FRAME \
  501. { register CORE_ADDR sp = read_register (SP_REGNUM);            \
  502.   register int regnum;                                \
  503.   char buf[8];                                    \
  504.   long word;                                \
  505.   for (regnum = S0_REGNUM; regnum >= S7_REGNUM; --regnum) {         \
  506.     read_register_bytes (REGISTER_BYTE (regnum), buf, 8);         \
  507.     sp = push_bytes (sp, buf, 8);}                        \
  508.   for (regnum = SP_REGNUM; regnum >= FP_REGNUM; --regnum) {         \
  509.     word = read_register (regnum);                    \
  510.     sp = push_bytes (sp, &word, 4);}                       \
  511.   word = (read_register (PS_REGNUM) &~ (3<<25)) | (1<<25);        \
  512.   sp = push_bytes (sp, &word, 4);                     \
  513.   word = read_register (PC_REGNUM);                    \
  514.   sp = push_bytes (sp, &word, 4);                       \
  515.   write_register (SP_REGNUM, sp);                        \
  516.   write_register (FP_REGNUM, sp);                        \
  517.   write_register (AP_REGNUM, sp);}
  518.  
  519. /* Discard from the stack the innermost frame, restoring all registers.  */
  520.  
  521. #define POP_FRAME  do {\
  522.   register CORE_ADDR fp = read_register (FP_REGNUM);        \
  523.   register int regnum;                        \
  524.   register int frame_length =    /* 3 short, 2 long, 1 extended, 0 context */ \
  525.       (read_memory_integer (fp + 4, 4) >> 25) & 3;          \
  526.   char buf[8];                                \
  527.   write_register (PC_REGNUM, read_memory_integer (fp, 4));  \
  528.   write_register (PS_REGNUM, read_memory_integer (fp += 4, 4));  \
  529.   write_register (FP_REGNUM, read_memory_integer (fp += 4, 4));  \
  530.   write_register (AP_REGNUM, read_memory_integer (fp += 4, 4));  \
  531.   if (frame_length < 3)                      \
  532.     for (regnum = A5_REGNUM; regnum < SP_REGNUM; ++regnum)   \
  533.       write_register (regnum, read_memory_integer (fp += 4, 4)); \
  534.   if (frame_length < 2)                         \
  535.     write_register (SP_REGNUM, read_memory_integer (fp += 4, 4)); \
  536.   fp -= 4;                            \
  537.   if (frame_length < 3)                      \
  538.     for (regnum = S7_REGNUM; regnum < S0_REGNUM; ++regnum) {    \
  539.       read_memory (fp += 8, buf, 8);                \
  540.       write_register_bytes (REGISTER_BYTE (regnum), buf, 8);}   \
  541.   if (frame_length < 2)    {                    \
  542.     read_memory (fp += 8, buf, 8);                \
  543.     write_register_bytes (REGISTER_BYTE (regnum), buf, 8);}     \
  544.   else write_register (SP_REGNUM, fp + 8);            \
  545.   flush_cached_frames ();                    \
  546.   set_current_frame (create_new_frame (read_register (FP_REGNUM), \
  547.                        read_pc ()));         \
  548. } while (0)
  549.  
  550. /* This sequence of words is the instructions
  551.      mov sp,ap
  552.      pshea 69696969
  553.      calls 32323232
  554.      bkpt
  555.    Note this is 16 bytes.  */
  556.  
  557. #define CALL_DUMMY {0x50860d4069696969LL,0x2140323232327d50LL}
  558.  
  559. #define CALL_DUMMY_START_OFFSET 0
  560.  
  561. /* Insert the specified number of args and function address
  562.    into a call sequence of the above form stored at DUMMYNAME.  */
  563.  
  564. #define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, type)   \
  565. { *(int *)((char *) dummyname + 4) = nargs;    \
  566.   *(int *)((char *) dummyname + 10) = fun; }
  567.  
  568. /* Defs to read soff symbol tables, see dbxread.c */
  569.  
  570. #define NUMBER_OF_SYMBOLS    ((long) opthdr.o_nsyms)
  571. #define STRING_TABLE_OFFSET  ((long) filehdr.h_strptr)
  572. #define SYMBOL_TABLE_OFFSET  ((long) opthdr.o_symptr)
  573. #define STRING_TABLE_SIZE    ((long) filehdr.h_strsiz)
  574. #define SIZE_OF_TEXT_SEGMENT ((long) txthdr.s_size)
  575. #define ENTRY_POINT          ((long) opthdr.o_entry)
  576.  
  577. #define READ_STRING_TABLE_SIZE(BUFFER) \
  578.     (BUFFER = STRING_TABLE_SIZE)
  579.  
  580. #define DECLARE_FILE_HEADERS \
  581.   FILEHDR filehdr;                            \
  582.   OPTHDR opthdr;                            \
  583.   SCNHDR txthdr
  584.  
  585. #define READ_FILE_HEADERS(DESC,NAME) \
  586. {                                    \
  587.   int n;                                \
  588.   val = myread (DESC, &filehdr, sizeof filehdr);            \
  589.   if (val < 0)                                \
  590.     perror_with_name (NAME);                        \
  591.   if (! IS_SOFF_MAGIC (filehdr.h_magic))                \
  592.     error ("%s: not an executable file.", NAME);            \
  593.   lseek (DESC, 0L, 0);                            \
  594.   if (myread (DESC, &filehdr, sizeof filehdr) < 0)            \
  595.     perror_with_name (NAME);                        \
  596.   if (myread (DESC, &opthdr, filehdr.h_opthdr) <= 0)            \
  597.     perror_with_name (NAME);                        \
  598.   for (n = 0; n < filehdr.h_nscns; n++)                    \
  599.     {                                    \
  600.       if (myread (DESC, &txthdr, sizeof txthdr) < 0)            \
  601.     perror_with_name (NAME);                    \
  602.       if ((txthdr.s_flags & S_TYPMASK) == S_TEXT)            \
  603.     break;                                \
  604.     }                                    \
  605. }
  606.  
  607. /* Interface definitions for kernel debugger KDB.  */
  608.  
  609. /* (no kdb) */
  610.